package org.springblade.resource.constant;

import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.utils.DesUtil;
import org.springblade.resource.vo.SafeBladeFile;
import org.springframework.beans.BeanUtils;

public interface OssConstant {

    public final static String KEY = "d9O5Bz1HIM7TY0K9vhkcgyu9t4Lpt0";

    public final static String SALT = "Rbo9m2Ntw7auR1R^9OSS:";

    public static SafeBladeFile toSafeBladeFile(BladeFile bladeFile){
        String name = bladeFile.getName();
        name = OssConstant.SALT+ name;
        SafeBladeFile safeBladeFile = new SafeBladeFile();
        BeanUtils.copyProperties(bladeFile,safeBladeFile);
        String encodeName = DesUtil.encryptToBase64(name, OssConstant.KEY);
        safeBladeFile.setEncodeName(encodeName);
        return safeBladeFile;
    }

    public static String getOssName(String encodeName){
        String saltName = DesUtil.decryptFormBase64(encodeName, OssConstant.KEY);
        if (saltName != null) {
            return saltName.replace(SALT, "");
        }
        return null;
    }
}
